package com.le.tester.leetcode;

/**
 * createTime：2024/4/26 13:47
 * description：盛最多水的容器,S(i,j)=min(h[i],h[j])×(j−i)
 */
public class MaxArea {
    public int maxArea(int[] height) {
        //左右两边最短得板向内移动
        int i = 0;
        int j = height.length - 1;
        int res = 0;

        while (i < j) {
            res = height[i] < height[j] ? Math.max(res, (j - i) * height[i++]) : Math.max(res, (j - i) * height[j--]);
        }
        return res;

    }

    public static void main(String[] args) {
        int[] arr = {1, 8, 6, 2, 5, 4, 8, 3, 7};
        System.out.println(new MaxArea().maxArea(arr));
    }
}
